const app = getApp(),
i = require("../../wxParse/wxParse.js"),
t = require("../../api.js");
 

Page({
  data: {
    id:1,
    page:1,
    store_id : 1,
    title : '',
    content: '',
    start_time : '',
    end_time: '',
    is_delete : 0,
    is_show : 1,
    addtime : '',
    sort: 1,
    see_num : 666,
    type : 1,
    bg_img: '',
    take_time : '',
    cover_img : '',
    img_list : '',
    list: [],
    is_load: 1,
    index: 0
  },
  onLoad: function (a) {
    console.log(111)
    app.pageOnLoad(this, a);
    this.getList();
  },
  getList: function () {
    var that = this;
    if (!that.data.is_load) {return false}
     wx.showLoading({
      title: '加载中',
    }),app.request({
      url: t.jielong.list,
      data: {
        page: that.data.page
      },
      success: function(res) {
        if (res.data.code == 0) {
          var new_list = that.data.list.concat(res.data.list);
          that.setData({
            list:new_list,
            page: ++that.data.page,
            is_load: res.data.is_load == 1? 1 : 0
          })
        }
      },
      complete: function () {
        wx.hideLoading()
      }
    })
  },
  onShow: function(){
    app.pageOnShow(this);
    wx.hideShareMenu();
    
  },
  // 显示分享
  showShareModal: function(tt) {
    console.log(tt);
    this.setData({
      share_modal_active: "active",
      no_scroll: !0,
      index: tt.currentTarget.dataset.index
    });
  },

  shareModalClose: function() {
    this.setData({
      share_modal_active: "",
      no_scroll: !1
    });
  },
  jielongQrcodeClose: function() {
    this.setData({
      qrcode_active: "",
      no_scroll: !1
    });
  },
  getQrcode: function() {
    var a = this;
    if (a.setData({
        qrcode_active: "active",
        share_modal_active: ""
      })) return !0;
    app.request({
      url: t.jielong.get_qrcode,
      data: {
        type: 7,
        id: a.data.list[a.data.index].id
      },
      success: function(t) {
        0 == t.code && a.setData({
          jielong_qrcode: t.data.pic_url
        }), 1 == t.code && (a.jielongQrcodeClose(), wx.showModal({
          title: "提示",
          content: t.msg,
          showCancel: !1,
          success: function(t) {
            t.confirm;
          }
        }));
      }
    });
  },
  saveQrcode: function() {
    var t = this;
    wx.saveImageToPhotosAlbum ? (wx.showLoading({
      title: "正在保存图片",
      mask: !1
    }), wx.downloadFile({
      url: t.data.jielong_qrcode,
      success: function(t) {
        wx.showLoading({
          title: "正在保存图片",
          mask: !1
        }), wx.saveImageToPhotosAlbum({
          filePath: t.tempFilePath,
          success: function() {
            wx.showModal({
              title: "提示",
              content: "海报保存成功",
              showCancel: !1
            });
          },
          fail: function(t) {
            wx.showModal({
              title: "图片保存失败",
              content: t.errMsg,
              showCancel: !1
            });
          },
          complete: function(t) {
            wx.hideLoading();
          }
        });
      },
      fail: function(a) {
        wx.showModal({
          title: "图片下载失败",
          content: a.errMsg + ";" + t.data.jielong_qrcode,
          showCancel: !1
        });
      },
      complete: function(t) {
        wx.hideLoading();
      }
    })) : wx.showModal({
      title: "提示",
      content: "当前版本过低，无法使用该功能，请升级到最新版本后重试。",
      showCancel: !1
    });
  },
  goodsQrcodeClick: function(t) {
    var a = t.currentTarget.dataset.src;
    wx.previewImage({
      urls: [a]
    });
  },
  //上拉加载
  onReachBottom: function () {
    this.getList();
   
  },
  onShareAppMessage: function(tt) {
    var index = this.data.index;
    var i = this;
    console.log(i.data.list[index].bg_img);
    return {
      path: "/jielong/edit/index?id=" + i.data.list[index].id,
      imageUrl: i.data.list[index].bg_img,
      title: i.data.list[index].title ,
      success: function (res) {
        wx.showModal({
          title: "提示",
          content: "d",
          showCancel: !1
        });
        if (res.errMsg == 'shareAppMessage:ok') {
          //分享为按钮转发
          if (that.data.shareBtn) {
            //判断是否分享到群
            if (res.hasOwnProperty('shareTickets')) {
              wx.showModal({
                title: "提示",
                content: "分享到群",
                showCancel: !1
              });
            } else {
              wx.showModal({
                title: "提示",
                content: "分享好友",
                showCancel: !1
              });
            }
          }
        } else {
          wx.showToast({
            title: '分享失败',
          })
        }
      }
    };
  },
})
